package com.guobo.user.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guobo.user.config.ResponseResult;
import com.guobo.user.entity.TUser;
import com.guobo.user.service.ITUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author guobo
 * @since 2021-05-05
 */
@RestController
@RequestMapping("/user")
//@CrossOrigin
public class TUserController {

    @Autowired
    ITUserService itUserService;

    @RequestMapping("login")
    public ResponseResult login(@RequestBody TUser user){

        //验证用户名或密码是否为空
        if(StringUtils.isBlank(user.getName()) || StringUtils.isBlank(user.getPassword())){
            return ResponseResult.fail(10000,"用户名或密码不能为空");
        }
        //验证用户是否存在
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("name",user.getName());
        TUser userInfo = itUserService.getOne(queryWrapper);
        if(userInfo==null){
            return ResponseResult.fail(10000,"用户不存在");
        }
        //验证密码是否正确
        if(!user.getPassword().equals(userInfo.getPassword())){
            return ResponseResult.fail(10000,"用户名或密码错误");
        }
//        boolean b=itUserService.getNameAndPwd(user);
        return ResponseResult.success(userInfo);
    }


}
